﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports ADOEntity

Public Class clsCheckApprove
    Dim UserEntity As UserEntities = New UserEntities
    Dim clsEdmUser As clsEdmUser = New clsEdmUser

    Function checkRightApprove(ByVal userCode As String, ByVal userNameL As String, ByVal roleCode As String, _
                               ByVal branchCode As String, ByVal ZoneCode As String, ByVal depCode As String, _
                               ByVal strPwd As String) As String

        Dim str As String = ""
        Dim qryApp = (From App In UserEntity.SUSER
                           Where App.USERNAME = userCode
                          Select App).ToList

        If qryApp.Count = 0 Then
            str = "รหัสผู้อนุมัติ ไม่ถูกต้อง"
        ElseIf Not clsEdmUser.checkPasswordLogin(qryApp(0).PASSWORD, strPwd) Then
            str = "รหัสผ่านผู้อนุมัติ ไม่ถูกต้อง"
        ElseIf qryApp(0).ROLECODE > 79 Or roleCode > 79 Then
            GoTo Complete
        ElseIf (qryApp(0).ROLECODE = 1) Or (qryApp(0).USERNAME = userNameL) Or (qryApp(0).ROLECODE < 60 And Not qryApp(0).BRANCHCODE = branchCode) Or (qryApp(0).ROLECODE < 70 And Not qryApp(0).ZONECODE = ZoneCode) Or (qryApp(0).ROLECODE < 80 And Not qryApp(0).DEPTCODE = depCode) Then
            str = "รหัส " + userCode + " ไม่มีสิทธิ์อนุมัติ"
        ElseIf Not qryApp(0).APPROVERIGHT.ToString = "1" Then
            str = "รหัส " + userCode + " ไม่ได้รับสืทธิ์ในการอนุมัติ"
        End If

Complete:
        Return str

    End Function

End Class
